<?php
/**
 * Created by PhpStorm.
 * User: Gooraye
 * Date: 2017-02-23
 * Time: 11:39
 */
namespace app\admin\controller;

use app\src\video\logic\UserVideoLogic;
use app\src\system\logic\DatatreeLogicV2;
class Video extends Admin
{
    public function index(){


            $r = (new UserVideoLogic())->queryNoPaging();
        $this -> assign('list', $r['info']);
        return $this -> boye_display();
    }

    public function add(){
        if(IS_GET){
            return $this -> boye_display();
        }else{
            $name = $this->_param('name','');
            $url  = $this->_param('url','');

            $entity = array(
                'name'=>$name,
                'url'=>$url
            );
            $result = (new UserVideoLogic())->add($entity);
            if(!$result['status']){
                $this->error($result['info']);
            }
            $this->success("保存成功！",url('Admin/Video/index'));

        }
    }


    public function edit(){
        $id = $this->_param('id',0);
        if(IS_GET){
            $result = (new UserVideoLogic())->getInfo(['id'=>$id]);
            if(!$result['status']){
                $this->error($result['info']);
            }

            $this->assign("info",$result['info']);
           // dump($result['info']);
            return $this -> boye_display();
        }else{
            $name = $this->_param('name');
            $url = $this->_param('url');
            $entity = array(
                'name'=>$name,
                'url'=>$url
            );
            $result = (new UserVideoLogic())->saveByID($id,$entity);

            if(!$result['status']){
                $this->error($result['info']);
            }
            $this->success("保存成功！",url('Admin/Video/index'));
        }
    }

    public function delete(){
        $id = $this->_param('id',0);
        $result = (new UserVideoLogic())->delete(array('id'=>$id));

        if(!$result['status']){
            $this->error($result['info']);
        }

        $this->success("删除成功！",url('Admin/Video/index'));

    }

    //批量删除
    public function delete_all(){
        $tids   = $this->_param('ids','');
        if($tids == '' || count($tids) == 0){
            $this -> success('操作成功');
        }
        $result = (new UserVideoLogic())->delete(['id'=>array('in',$tids)]);

        if($result['status']){
            $this -> success("操作成功");
        }else{
            $this -> error($result['info']);
        }

    }
}